<template>
  <div>
    <el-row>
      <el-col :span="24">
        <el-button type="primary" @click="addSupplier">新增供应商</el-button>
        <el-button type="success" @click="editSupplier">编辑</el-button>
        <el-button type="danger" @click="deleteSupplier">删除</el-button>
        <el-button type="success" @click="getUnitList">搜索</el-button>
      </el-col>
    </el-row>
    <!--表格区域-->
    <el-card class="box-card">
      <el-table
        :data="suppliers"
        @selection-change="handleSelectionChange"
        style="width: 100%">
        <el-table-column
          type="selection"
          width="55">
        </el-table-column>
        <el-table-column
          type="index"
          label="序号"
          width="50">
          <template slot-scope="scope">
            {{ (pageNum - 1) * pageSize + scope.$index + 1 }}
          </template>
        </el-table-column>
        <el-table-column
          prop="supplierId"
          label="供应商ID">
        </el-table-column>
        <el-table-column
          prop="supplierName"
          label="供应商">
        </el-table-column>
        <el-table-column
          prop="supplierCategory"
          label="供应商类别">
        </el-table-column>
        <el-table-column
          prop="contactPerson"
          label="联系人">
        </el-table-column>
        <el-table-column
          prop="contactPhone"
          label="联系电话">
        </el-table-column>
        <el-table-column
          prop="paymentMethod"
          label="付款方式">
        </el-table-column>
        <el-table-column
          prop="address"
          label="地址">
        </el-table-column>
        <el-table-column
          prop="createdAt"
          label="创建时间">
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button
              size="mini"
              @click="update(scope.row)"
              icon="el-icon-circle-plus-outline">
            </el-button>
            <el-button
              size="mini"
              type="danger"
              @click="delUnit(scope.row)" icon="el-icon-circle-close">
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="pageNum"
        :page-sizes="[2, 3, 4, 5]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total">
      </el-pagination>
    </el-card>
  </div>
</template>

<script>
import { getList } from '@/api/supplier'

export default {
  name: 'Supplier',
  data() {
    return {
      suppliers: [],
      pageNum: 1,
      pageSize: 5,
      total: 0,
      dialogVisible: false,
      listVisible: false,
      title: "",
    };
  },
  methods: {
    addSupplier() {
      // 添加供应商的逻辑
    },
    editSupplier() {
      // 编辑供应商的逻辑
    },
    deleteSupplier() {
      // 删除供应商的逻辑
    },
    getUnitList() {
      getList({
        pageNum: this.pageNum,
        pageSize: this.pageSize,
      }).then(res => {
        // console.log("获取单位列表成功", res)
        // res.data取出的是pageinfo对象，里面包含list和total属性
        this.suppliers = res.data.list;
        this.total = res.data.total;
      });
    },
    // 处理分页
    handleSizeChange(size) {
      this.pageSize = size;
      this.getUnitList();
    },
    handleCurrentChange(currentPage) {
      this.pageNum = currentPage;
      this.getUnitList();
    },
    // 处理复选框
    handleSelectionChange(val) {
      let ids = [];
      ids = val.map(e =>e.id)
      this.ids = ids;
    },
  },
  created() {
    this.getUnitList();
  },
}
</script>

<style scoped>
/* 样式调整 */
</style>
